package 蓝桥.十五届;

import java.util.Arrays;

/**
 * @author ZhuYi
 * @create 2025/3/20 23:07
 */
public class B类斐波那契循环数 {
    public static void main(String[] args) {
        for (int i = 10000000; i > 0; i--) {
            if (check(i)) {
                System.out.println(i);
                break;
            }
        }
    }

    public static boolean check(int i) {
        String s = i + "";
        char[] chars = s.toCharArray();
        int[] dp = new int[10000010];
        for (int j = 0; j < chars.length; j++) {
            dp[j] = chars[j] - '0';
        }

        dp[chars.length] = Arrays.stream(dp).sum();
        int j = chars.length + 1;
        while (true) {
            for (int m = 1; m <= chars.length; m++) {
                dp[j] += dp[j - m];
            }
            if (dp[j] == i) {
                return true;
            }
            if (dp[j] > i) {
                break;
            }
            j++;
        }
        return false;
    }
}
